<?php

/**
 * FTP helper class
 *
 * @author jordan.stevens
 */
class ftp {
	var $connect;
	var $localDirectory;
	var $remoteDirectory;
	var $currentDirectory;
	public function __construct($ftpFile)
	{
		$this->remoteDirectory = dirname($ftpFile);
		$params = parse_ini_file($ftpFile);
		$this->connect = ftp_connect($params['server']);
		ftp_login($this->connect, $params['username'], $params['password']);
		ftp_chdir($this->connect, $params['directory']);
	}
	public function synchronize($dir,$file)
	{
		$this->chdir($dir);
		ftp_put($this->connect, $file, $file, FTP_BINARY);
	}
	public function close()
	{
		ftp_close($this->connect);
	}
	public function chdir($dir)
	{
		if($currentDirectory!=$dir) {
			ftp_chdir($this->connect,$this->remoteDirectory + '/' + $dir);
			$currentDirectory=$dir;
		}
	}
}

?>
